package com.wzy.netty.nio;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 描述  : 读取文件
 * 创建人:    Wzy
 * 创建时间: 2020-06-10  14:21
 */
@Slf4j
public class NIOFileChannel02 {
    public static void main(String[] args) throws IOException {
        File file = new File("01.txt");
        FileInputStream inputStream = new FileInputStream(file);
        FileChannel fileChannel = inputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate((int) file.length());
        //数据从channel 读取到 buffer
        fileChannel.read(buffer);
        //返回字节数组
        log.info(new String(buffer.array()));

        inputStream.close();
    }
}
